package com.crm.CLdriving.controller;

import java.util.List;

import javax.validation.Valid;

import com.crm.CLdriving.common.PageResponse;
import com.crm.CLdriving.dto.PageReq.PageNumber;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;
import com.crm.CLdriving.common.BaseResponse;
import com.crm.CLdriving.dto.req.CoachDeleteReqDto;
import com.crm.CLdriving.dto.req.CoachInputReqDto;
import com.crm.CLdriving.dto.req.CoachInsertReqDto;
import com.crm.CLdriving.dto.req.CoachSelOneReqDto;
import com.crm.CLdriving.dto.req.CoachUpdateReqDto;
import com.crm.CLdriving.dto.resp.CoachSelectAllRespDto;
import com.crm.CLdriving.dto.resp.CoachSelectOneRespDto;
import com.crm.CLdriving.enu.ResponseEnum;
import com.crm.CLdriving.po.CoachPO;
import com.crm.CLdriving.service.CoachService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.log4j.Log4j2;

@Controller
@RequestMapping("coach")
@Log4j2
@Api(tags="教练信息管理")
public class CoachController {
	
	@Autowired
	private CoachService coachService;

	@PostMapping("insert")
	@ResponseBody
	@ApiOperation("录入教练信息接口")
	public BaseResponse<?> insert(@Valid @RequestBody CoachInsertReqDto coachInsertReqDto) {
		log.info(""+JSON.toJSONString(coachInsertReqDto));
		return coachService.insert(coachInsertReqDto);
	}
	
	@PostMapping("selectInput")
	@ResponseBody
	@ApiOperation("筛选框查询教练信息接口")
	public BaseResponse<List<CoachPO>> SelectInput(@RequestBody @Valid CoachInputReqDto coachInputReqDto){
		log.info("筛选框查询教练信息请求："+JSON.toJSONString(coachInputReqDto));
		if ((coachInputReqDto.getIdentity()==null || coachInputReqDto.getIdentity()=="") &&
				(coachInputReqDto.getName()==null || coachInputReqDto.getName()=="")) {
			return BaseResponse.message(ResponseEnum.MYSXTJ);
		}
		return coachService.selectInput(coachInputReqDto);
	}
	
	@PostMapping("selectall")
	@ResponseBody
	@ApiOperation("查询 全部教练信息接口")
	public PageResponse<List<CoachSelectAllRespDto>> SelectAll(@RequestBody PageNumber pageNumber) {
		return coachService.selectall(pageNumber);
	}
	
	@PostMapping("selectone")
	@ResponseBody
	@ApiOperation("查询  教练信息接口")
	public BaseResponse<CoachSelectOneRespDto> SelectOne(@Valid @RequestBody CoachSelOneReqDto coachSelOneReqDto){
		log.info(""+JSON.toJSONString(coachSelOneReqDto));
		return coachService.selectone(coachSelOneReqDto);	
	}
	
	@PostMapping("update")
	@ResponseBody
	@ApiOperation("更新教练信息接口")
	public BaseResponse<?> update(@Valid @RequestBody CoachUpdateReqDto coachUpdateReqDto){
		log.info(""+JSON.toJSONString(coachUpdateReqDto));
		return coachService.update(coachUpdateReqDto);
	}
	
	@PostMapping("delete")
	@ResponseBody
	@ApiOperation("删除教练信息接口")
	public BaseResponse<?> Delete(@Valid @RequestBody CoachDeleteReqDto coachDeleteReqDto){
		log.info(""+JSON.toJSONString(coachDeleteReqDto));
		return coachService.delete(coachDeleteReqDto);
	}
	
}
